local love = require 'love'

local setColor = love.graphics.setColor
local circle = love.graphics.circle
local drawRectangle = love.graphics.rectangle
local setLineWidth = love.graphics.setLineWidth

local padding = Padding

-- 指导圆圈
local instructionsButton = {
    x = 0,
    y = 0,
    radius = 0,
    mainBody = {
        x = 0,
        y = 0,
        width = 0,
        height = 0
        },
    bottomPoint = {
        x = 0,
        y = 0,
        radius = 0
    },
    colors = {
        isPressed = {0.25, 0.35, 0.5},  -- 比背景色略深、比边框色稍亮
        isHovered = {0.4, 0.6, 0.8},  -- 比普通状态的背景色再浅一个色调
        normal = {0.3, 0.5, 0.7},  -- 比背景色浅一个色调
        border = {0.1, 0.3, 0.5},  -- 比背景色深一个色调
        exclamation = {0.9, 0.7, 0.2}  --明亮的金黄色，确保标志可见
    },
    isHovered = false,
    isPressed = false
}

local function init()
    local circleRadius = 10
    instructionsButton.x = padding + circleRadius
    instructionsButton.y = padding + circleRadius
    instructionsButton.radius = circleRadius

    instructionsButton.mainBody.x = instructionsButton.x - circleRadius * 0.15
    instructionsButton.mainBody.y = instructionsButton.y - circleRadius * 0.6
    instructionsButton.mainBody.width = circleRadius * 0.3
    instructionsButton.mainBody.height = circleRadius * 0.8

    instructionsButton.bottomPoint.x = instructionsButton.x
    instructionsButton.bottomPoint.y = instructionsButton.y + circleRadius * 0.5
    instructionsButton.bottomPoint.radius = circleRadius * 0.22
end

local function drawButton()
    -- 绘制按钮
    if instructionsButton.isPressed then
        setColor(instructionsButton.colors.isPressed)  -- 比背景色略深、比边框色稍亮，通过降低亮度和饱和度营造「凹陷感」，模拟物理按钮的按下效果
    elseif instructionsButton.isHovered then
        setColor(instructionsButton.colors.isHovered)  -- 比普通状态的背景色再浅一个色调
    else
        setColor(instructionsButton.colors.normal) -- 比背景色浅一个色调
    end
    circle("fill", instructionsButton.x, instructionsButton.y, instructionsButton.radius)

    -- 绘制按钮边框
    setColor(instructionsButton.colors.border) -- 比背景色深一个色调
    setLineWidth(2)
    circle("line", instructionsButton.x, instructionsButton.y, instructionsButton.radius)

    -- 绘制感叹号
    setColor(instructionsButton.colors.exclamation)
    -- 感叹号的主体
    drawRectangle("fill", instructionsButton.mainBody.x, instructionsButton.mainBody.y, instructionsButton.mainBody.width, instructionsButton.mainBody.height)
    -- 感叹号的点
    circle("fill", instructionsButton.bottomPoint.x, instructionsButton.bottomPoint.y, instructionsButton.bottomPoint.radius)
end

local function inArea(x, y)
    return x >= instructionsButton.x - instructionsButton.radius and
           x <= instructionsButton.x + instructionsButton.radius and
           y >= instructionsButton.y - instructionsButton.radius and
           y <= instructionsButton.y + instructionsButton.radius
end

local function isHovered(boolean)
    instructionsButton.isHovered = boolean
end

local function isPressed()
    instructionsButton.isPressed = true
end

local function isReleased()
    instructionsButton.isPressed = false
end

return{
    init = init,
    drawButton = drawButton,
    inArea = inArea,
    isHovered = isHovered,
    isPressed = isPressed,
    isReleased = isReleased
}